#include <graphics.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdio.h>

using namespace std;

 class POLE
{
      double x;
      double y;
      double a;
      double Kq;
      double vx;
      double vy;
      
    public :
      POLE (double x1,double y1,double Kq1,double vx1,double vy1 )
      {
         x=x1;
         y=y1;
         Kq=Kq1;
         a=Kq/((x-600)*(x-600)+(y-350)*(y-350));
         vx=vx1;
         vy=vy1; 
      }
      
      ~POLE(void)
      {
         x=0;
         y=0;
         a=0;
         Kq=0;
         vx=0;
         vy=0;
      }
      
      void RKP(void)
      {
        float dt;
        if ((x>=580) and (x<=620) and (y>=330) and (y<=370)) (dt=0);
        else dt=0.1;
        a=Kq/((x-600)*(x-600)+(y-350)*(y-350));
        vx=vx+a*(600-x)/sqrt((x-600)*(x-600)+(y-350)*(y-350))*dt;
        vy=vy+a*(350-y)/sqrt((x-600)*(x-600)+(y-350)*(y-350))*dt;
        x=x+(vx*dt);
        y=y+(vy*dt);
      }
      
      void COLOR(int a, int b)
      {
          setfillstyle(a,b);
          fillellipse((int)x,(int)y, 5, 5);     
      }
                
};
    
      
int main()
{
    float t1, t, L, x, y, vx, vy, q, m, f;
    double GK, MQ, kq;
    cout<<"   Vvod nachalnyh dannih\n";
    cout<<"centr polya: x=600, y=350\n";
    cout<<"Vvedite vid central'nogo polya:\n";
    cout<<"Gravitacionnoe   - 0\n";
    cout<<"Electricheskoe+  - 1\n";
    cin>>GK;
    cout<<"Dlya vvoda znacheniy po umolchaniu vvedite - 1\n";
    cout<<"Dlya vvoda sobstvennih znacheniy vvedite   - 0\n";
    cin>>f;
    if (f==0)
    {
       cout<<"Vvedite massu ili zaryad centralnogo tela:\n";
       cout<<"Po umolchaniu: 10^13 ; 3\n";
       cin>>MQ;
       cout<<"Vvedite massu chasticy:\n";
       cout<<"dlya gravitacionnogo polya vvedite 0:\n";
       cout<<"Po umolchaniu: 0 ; 30\n";
       cin>>m;
       cout<<"Vvedite zaryad chasticy:\n";
       cout<<"dlya gravitacionnogo polya vvedite 0:\n";
       cout<<"Po umolchaniu: 0 ; 0.000001\n";
       cin>>q;
       cout<<"Vvedite koordinatu chasticy po x:\n"; 
       cout<<"Po umolchaniu:700\n";
       cin>>x;
       cout<<"Vvedite koordinatu chasticy po y:\n"; 
       cout<<"Po umolchaniu:300\n";
       cin>>y;
       cout<<"Vvedite skorost' chasticy po x:\n";
       cout<<"Po umolchaniu:-1\n";
       cin>>vx;
       cout<<"Vvedite skorost' chasticy po y:\n";
       cout<<"Po umolchaniu:-2\n";
       cin>>vy;
       cout<<"Vvedite vremya dvizenia:\n";
       cout<<"Esli bez ogranicheniy po vremeny, to vvedite 0\n";
       cout<<"Po umolchaniu:0\n";
       cin>>t;
    } 
    if ((f==1) and (GK==0))
    {
       MQ=1000000000;
       MQ=MQ*10000;
       x=700;
       y=300;
       vx=-1;
       vy=-2;
       t=0;
    }
    if ((f==1) and (GK==1))
    {
       MQ=3;
       m=30;
       q=0.000001;
       x=700;
       y=300;
       vx=-1;
       vy=-2;
       t=0;
    }
    
    initwindow(1200, 700);
    
    if (GK==0)  GK=0.0000000000667;
    if (GK==1)  GK=q/m*898755179*10; 
    kq=MQ*GK;
      
    POLE P(x,y,kq,vx,vy);  
       
    L=1;
    if (t==0) L=0;
     
    t1=0;
    
    while ((t1<=t) or (L==0))
    {

    P.RKP();
    
    fillellipse(600, 350, 25, 25);
     
    P.COLOR(1, BLUE);
    
    t1=t1+0.1;      
    } 
    getch();
    closegraph();
    return 0;
}
